$(function(){
	$(".selector").each(function() {
		 $(this).selectorInit();
	});	
	//覆写日历click方法
	var cur_idx = null;
	JCalendar.click = function(obj){
		JCalendar.cur_date = parseInt(obj.innerHTML);
		if (JCalendar.onclick) {
			var dt = new Date(JCalendar.cur_year, JCalendar.cur_month - 1, JCalendar.cur_date);
			JCalendar.onclick(JCalendar.cur_year,JCalendar.cur_month,JCalendar.cur_date);
		}
	}
	JCalendar.onclick = function(year, month, date) {
		if($("#"+cur_idx).attr('rel') == 'time'){
			$("#"+cur_idx).val( year + "-" + month + "-" + date);
		}else{
			$("#"+cur_idx).val( year + "-" + month + "-" + date + " 00:00:00");
		}
		if(layer){
			layer.hide();
		}
	}
	var layer = $("<div></div>").css({
		"display": "none",
		"position": "absolute",
		"z-index": "2010"
	}).html(new JCalendar().show()).appendTo(document.body);
	$(".click_calendar").click(function() {
		layer.show();
		var pos = $(this).offset();
		layer.css({
			"left": pos.left,
			"top": pos.top
		});
		cur_idx = $(this).attr("id").split("_").pop();
		return false;
	});
	
	//审核通过
	$(".webpage_pass").click(function(){
		var id = $(this).attr('rel');
		var webpage_id = $(this).attr('webpage');
		var action = 'wpPowerAuditPass';
		var interface_str = $(this).attr('interface');
		var url = "aj_wpPower.php";
		showCommonLayer('确定通过吗？', 2, function(){
			var post = {action:action, id:id, webpage_id:webpage_id, interface_str:interface_str};
			$.post(url, post, function(json){
				if(1 == json.status){
					showCommonLayer('审核通过成功', 4);
					window.location.reload();
				}else{
					showCommonLayer(json.msg, 5);
				}
			}, 'json');
		});
	});
	//审核驳回
	$(".webpage_refuse").click(function(){
		var id = $(this).attr('rel');
		var action = 'wpPowerAuditRefuse';
		var url = "aj_wpPower.php";
		
		showEditLayer("refuse_layer", "驳回理由", ["edit_layer_ok","edit_layer_cancel"],function(){
			if($(this).attr("id") != "edit_layer_ok") {
				return;
			}
			var refuse_reason = $("#refuse_reason").val();
			var post = {action:action, id:id, refuse_reason:refuse_reason};
			$.post(url, post, function(json){
				if(1 == json.status){
					showCommonLayer('审核驳回成功', 4);
					window.location.reload();
				}else{
					showCommonLayer(json.msg, 5);
				}
			}, 'json');
		});
	});
})
